package com.cxx.purchasecharge.core.crypto;

import org.apache.log4j.Logger;

/**
 * This CryptoFactory returns a Crypto implementation to the caller.
 * In the future, different implementations maybe needed.
 * For now just use AES implementation
 * 
 */
public class CryptoFactory
{
    private static final Logger logger = Logger.getLogger(CryptoFactory.class);
    
    /**
     * Returns an instance of the ICrypto implementation using the default keys and keySalt.
     * @return The ICrypto implementation
     * @throws CryptoException
     *            if there are any problems obtaining the required encryption
     *            algorithms.
     */             
    public static ICrypto getInstance() throws CryptoException
    {
//        ICrypto crypto = (ICrypto)new AESEncryption();
        ICrypto crypto = (ICrypto)new AESKeyStoreEncryption();
        return crypto;
    }
    
    /**
     * Returns an instance of the ICrypto implementation using the specified keys and the default salt.
     * @param keyText The key used to encrypt the data.
     * @return The ICrypto implementation
     * @throws CryptoException
     *             if there are any problems obtaining the required encryption
     *             algorithms.
     */
    public static ICrypto getInstance(String keyText) throws CryptoException
    {
        ICrypto crypto = (ICrypto)new AESEncryption(keyText);
        return crypto;
    }
    
    /**
     * Returns an instance of the ICrypto implementation using the specified keys and salt.
     * @param keyText The key used to encrypt the data.
     * @param keySalt The salt used by the encryption/decryption.
     * @return The ICrypto implementation
     * @throws CryptoException
     *             if there are any problems obtaining the required encryption
     *             algorithms.
     */
    public static ICrypto getInstance(String keyText, byte[] keySalt) throws CryptoException
    {
        ICrypto crypto = (ICrypto)new AESEncryption(keyText, keySalt);
        return crypto;
    }   
}
